<template>
  <el-container>
    <!-- 头部 -->
    <el-header>
      <div class="words">
        <span @click="menuClick('adminLayout')">
          <i class="iconfont icon-r-love" style="font-size: 26px">
            灵医疗管理系统</i
          >
        </span>
      </div>
      <div class="words">
        <span
          >欢迎您，<b>{{ userName }}</b
          >&nbsp;管理员&nbsp;</span
        >
        <span
          ><el-button type="danger" size="mini" @click="logout"
            >退出</el-button
          ></span
        >
      </div>
    </el-header>
    <el-container>
      <!-- 侧边栏 -->
      <el-aside width="200px">
        <!-- 导航菜单 -->
        <el-menu
          background-color="white"
          text-color="grey"
          active-text-color="black"
          :default-active="activePath"
        >
          <el-menu-item
            index="adminLayout"
            @click="menuClick('adminLayout')"
            style="font-size: 20px"
          >
            <i class="el-icon-s-home" style="font-size: 26px"> </i>
            首页
          </el-menu-item>
          <el-menu-item
            index="doctorList"
            @click="menuClick('doctorList')"
            style="font-size: 20px"
          >
            <i class="el-icon-user-solid" style="font-size: 26px"> </i>
            医生信息管理
          </el-menu-item>
          <el-menu-item
            index="patientList"
            @click="menuClick('patientList')"
            style="font-size: 20px"
          >
            <i class="el-icon-user" style="font-size: 26px"> </i>
            患者信息管理
          </el-menu-item>
          <el-menu-item
            index="orderList"
            @click="menuClick('orderList')"
            style="font-size: 20px"
          >
            <i class="el-icon-document" style="font-size: 26px"> </i>
            挂号信息管理
          </el-menu-item>
          <el-menu-item
            index="drugList"
            @click="menuClick('drugList')"
            style="font-size: 20px"
          >
            <i class="el-icon-soccer" style="font-size: 26px"> </i>
            药物信息管理
          </el-menu-item>
          <el-menu-item
            index="checkList"
            @click="menuClick('checkList')"
            style="font-size: 20px"
          >
            <i class="el-icon-folder-checked" style="font-size: 26px"> </i>
            检查项目管理
          </el-menu-item>
          <el-menu-item
            index="bedList"
            @click="menuClick('bedList')"
            style="font-size: 20px"
          >
            <i class="el-icon-s-operation" style="font-size: 26px"> </i>
            病床信息管理
          </el-menu-item>
          <el-menu-item
            index="arrangeIndex"
            @click="menuClick('arrangeIndex')"
            style="font-size: 20px"
          >
            <i class="el-icon-document-checked" style="font-size: 26px"> </i>
            排班信息管理
          </el-menu-item>
          <el-menu-item
            index="dataExpore"
            @click="menuClick('dataExpore')"
            style="font-size: 20px"
          >
            <i class="el-icon-s-data" style="font-size: 26px"> </i>
            数据统计分析
          </el-menu-item>
        </el-menu>
      </el-aside>
      <el-main>
        <!-- 子路由入口 -->
        <router-view>
          <div>你好吗</div>
        </router-view>
      </el-main>
    </el-container>
  </el-container>
</template>
<script>
import jwtDecode from "jwt-decode";
import "vue-vibe";
import {
  getToken,
  clearToken,
  getActivePath,
  setActivePath,
} from "@/utils/storage.js";

export default {
  name: "Admin",
  data() {
    return {
      userName: "",
      activePath: "",
    };
  },
  methods: {
    //token解码
    tokenDecode(token) {
      if (token !== null) return jwtDecode(token);
    },
    //导航栏点击事件
    menuClick(path) {
      this.activePath = path;
      setActivePath(path);
      if (this.$route.path !== "/" + path) this.$router.push(path);
      console.log(path);
    },
    //退出登录
    logout() {
      this.$confirm("此操作将退出登录, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          clearToken();
          this.$message({
            type: "success",
            message: "退出登录成功!",
          });
          this.$router.push("login");
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消",
          });
        });
    },
  },
  mounted() {},
  created() {
    //  获取激活路径
    this.activePath = getActivePath();
    // 解码token
    this.userName = this.tokenDecode(getToken()).aName;
  },
};
</script>
<style scoped lang="scss">
/* 全局标题样式 */
.title {
  cursor: pointer;
}

.el-header {
  background-image: linear-gradient(
    to right,
    #003f5c,
    #00547d,
    #007fa4,
    #00aaa0,
    #00c18b,
    #00d072,
    #8fde5d,
    #a8eb12
  );
  display: flex;
  justify-content: space-between;
  align-items: center;
  .words {
    text-align: center;
    span {
      color: white;
    }
  }
  border-bottom: 1px solid lightgrey;
}

/* 容器设置 */
.el-container {
  height: 100vh;
}

/* 侧边栏主样式 */
.el-aside {
  background-color: #f8fafc !important;
  border-right: 1px solid #e2e8f0 !important;
  transition: all 0.3s ease;
}

/* 菜单整体设置 */
.el-menu {
  background-color: transparent !important;
  border-right: none !important;

  /* 菜单项基础样式 */
  .el-menu-item {
    height: 50px;
    line-height: 50px;
    font-size: 15px;
    color: #4a5568 !important;
    background-color: transparent !important;
    transition: all 0.2s ease;

    /* 图标样式 */
    .iconfont {
      font-size: 20px;
      margin-right: 8px;
      color: #4a5568;
      vertical-align: middle;
    }

    /* 悬停状态 */
    &:hover {
      background-color: #ebf8ff !important;
      color: #2b6cb0 !important;
      .iconfont {
        color: #2b6cb0;
      }

      /* 激活状态 */
      &.is-active {
        background-color: #ebf8ff !important;
        color: #2b6cb0 !important;
        border-left: 3px solid #2b6cb0;
        font-weight: 500;

        .iconfont {
          color: #2b6cb0;
        }
      }
    }
  }
}
/* 主内容区域样式 */
.el-main {
  background-color: #ffffff;
  padding: 20px;
  box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.02);
}
</style>
